﻿<!DOCTYPE html>

<html lang="en" xmlns="http://www.w3.org/1999/xhtml">
<head>
    <meta charset="utf-8" />
    <title></title>
</head>
<body>
    <script>
      /*  let arr = [1, 2, 3]*/
       // arr.push(4);
       // console.log(arr);
       //let push1 = function (num) {
       //     arr[arr.length] = num;
       // }
       // push1(5);
       // console.log(arr);

        //let arr1 = new Array();
        //console.log(arr1);
        //Array.push2 = function (sum) {
        //    Array[Array.length] = sum;
        //}
        //arr1.push2(1);
        //console.log(arr1);

        //arr.splice(3,0,2,2);
        //console.log(arr);



        //Array.prototype.splice1 = function () {
        //    console.log(arguments);
        //    for (var i = 0; i < arguments.length - 2; i++) {

        //        let unm = arguments[0]++;

        //        this[unm] = arguments[i + 2];

        //    }

        //}
        //arr.splice1(2,2,3,3,3);
        //console.log(arr);

        var arr1 = [2, 4, 5,6,7];
        function splice2(array,n,m) {
            m = m ? m : array.length - n; 
            for (var j = n + m, k = n; j < array.length; j++, k++) {
               array[k] = array[j];
            }
            array.length -= m;

            console.log(array.length);
            console.log(arguments.length);
            for (var i = array.length+arguments.length-4,j=array.length-1; i >=n; i--,j--) {
                array[i] = array[j];
            }
            console.log(arr1);
            for (var i = 0; i < arguments.length - 3; i++) {

                let unm = arguments[1]++;

                array[unm] = arguments[i + 3];

            }
        }
        splice2(arr1,2,2,2,4,3);
        console.log(arr1);


    </script>
</body>
</html>